import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  listLogEventTree = "/system-service/logEvent/listTree",
  listLogEvent = "/system-service/logEvent/list",
  getLogEvent = "/system-service/logEvent/get",
  saveLogEvent = "/system-service/logEvent/save",
  updateLogEvent = "/system-service/logEvent/update",
  deleteLogEvent = "/system-service/logEvent/delete",
  batchDeleteLogEvent = "/system-service/logEvent/batchDelete",
}

export const getLogEvent = (params) => defHttp.get({url : Api.getLogEvent, params})
export const listLogEvent = (params) => defHttp.get({url : Api.listLogEvent, params})
export const listLogEventTree = (params) => defHttp.get({url : Api.listLogEventTree, params})

export const saveOrUpdateLogEvent = (params, isUpdate) => {
  let url = isUpdate ? Api.updateLogEvent : Api.saveLogEvent;
  return defHttp.post({url: url, params});
}

export const deleteLogEvent = (params, handleSuccess) => {
  return defHttp.delete({url: Api.deleteLogEvent, data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteLogEvent = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.batchDeleteLogEvent, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
